#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

void dfs(vector<vector<int>> &gh, vector<int> &deep, int u, int f, int &md)
{
	deep[u] = deep[f] + 1;
	if (deep[u] > deep[md]) {
		md = u;
	}
	for (auto v : gh[u]) {
		if (v != f) {
			dfs(gh, deep, v, u, md);
		}
	}
}

void method_2dfs(vector<vector<int>> &gh, vector<int> &deep)
{
	int md = 0;
	dfs(gh, deep, 1, 0, md);

	fill(deep.begin(), deep.end(), 0);
	deep[0] = -1;
	int md2 = 0;
	dfs(gh, deep, md, 0, md2);

	cout << deep[md2] << endl;
}

long dp(vector<vector<int>> &gh, int u, int f, long &md)
{
	long max1 = 0;
	long max2 = 0;
	for (auto v : gh[u]) {
		if (v != f) {
			long child_max = dp(gh, v, u, md) + 1;
			if (child_max > max1) {
                                max2 = max1;
                                max1 = child_max;
			}else if(child_max > max2){
                                max2 = child_max;
                        }
		}
	}
        md = max(md, max1 + max2);
        return max1;
}

long dp2(vector<vector<int>> &gh, int u, int f, long &md)
{
	long mdist = 0;
	for (auto v : gh[u]) {
		if (v != f) {
			long child_mdist = dp(gh, v, u, md);
                        md = max(md, mdist + child_mdist + 1);
			mdist = max(mdist, child_mdist + 1);
		}
	}
        return mdist;
}

void method_dp(vector<vector<int>> &gh)
{
        long md = 0;
        dp2(gh, 1, 0, md);
        cout << md << endl;
}

int main()
{
	int n = 0;
	cin >> n;
	vector<vector<int>> gh(n + 1);
	vector<int> deep(n + 1, 0);

	deep[0] = -1;
	for (int i = 0, u, v; i < n - 1; i++) {
		cin >> u >> v;
		gh[u].push_back(v);
		gh[v].push_back(u);
	}

	//method_2dfs(gh, deep);
        method_dp(gh);

	return 0;
}